;;; $DOOMDIR/config.el -*- lexical-binding: t; -*-

;; Place your private configuration here! Remember, you do not need to run 'doom
;; sync' after modifying this file!


;; Some functionality uses this to identify you, e.g. GPG configuration, email
;; clients, file templates and snippets. It is optional.
(setq user-full-name "xdash-bw"
      user-mail-address "xdashproject@gmail.com")

;; Doom exposes five (optional) variables for controlling fonts in Doom:
;;
;; - `doom-font' -- the primary font to use
;; - `doom-variable-pitch-font' -- a non-monospace font (where applicable)
;; - `doom-big-font' -- used for `doom-big-font-mode'; use this for
;;   presentations or streaming.
;; - `doom-unicode-font' -- for unicode glyphs
;; - `doom-serif-font' -- for the `fixed-pitch-serif' face
;;
;; See 'C-h v doom-font' for documentation and more examples of what they
;; accept. For example:
;;

(setq doom-font (font-spec :family "Inconsolata" :weight 'normal :size 18))
;;
;; If you or Emacs can't find your font, use 'M-x describe-font' to look them
;; up, `M-x eval-region' to execute elisp code, and 'M-x doom/reload-font' to
;; refresh your font settings. If Emacs still can't find your font, it likely
;; wasn't installed correctly. Font issues are rarely Doom issues!

;; There are two ways to load a theme. Both assume the theme is installed and
;; available. You can either set `doom-theme' or manually load a theme with the
;; `load-theme' function. This is the default:

;; (setq doom-theme 'doom-dracula)
(setq doom-theme 'doom-one)

;; This determines the style of line numbers in effect. If set to `nil', line
;; numbers are disabled. For relative line numbers, set this to `relative'.
(setq display-line-numbers-type t)

;; If you use `org' and don't want your org files in the default location below,
;; change `org-directory'. It must be set before org loads!
(setq org-directory "~/org/")


;; Whenever you reconfigure a package, make sure to wrap your config in an
;; `after!' block, otherwise Doom's defaults may override your settings. E.g.
;;
;;   (after! PACKAGE
;;     (setq x y))
;;
;; The exceptions to this rule:
;;
;;   - Setting file/directory variables (like `org-directory')
;;   - Setting variables which explicitly tell you to set them before their
;;     package is loaded (see 'C-h v VARIABLE' to look up their documentation).
;;   - Setting doom variables (which start with 'doom-' or '+').
;;
;; Here are some additional functions/macros that will help you configure Doom.
;;
;; - `load!' for loading external *.el files relative to this one
;; - `use-package!' for configuring packages
;; - `after!' for running code after a package has loaded
;; - `add-load-path!' for adding directories to the `load-path', relative to
;;   this file. Emacs searches the `load-path' when you load packages with
;;   `require' or `use-package'.
;; - `map!' for binding new keys
;;
;; To get information about any of these functions/macros, move the cursor over
;; the highlighted symbol at press 'K' (non-evil users must press 'C-c c k').
;; This will open documentation for it, including demos of how they are used.
;; Alternatively, use `C-h o' to look up a symbol (functions, variables, faces,
;; etc).
;;
;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how
;; they are implemented.


;; ------------------------------------------
;; global On/Off
;; ------------------------------------------
(setq evil-escape-key-sequence "fd")
(global-set-key (kbd "M-o") (kbd "C-z"))
(global-set-key (kbd "M-i") 'toggle-input-method)

;;------------------------------------------------------------
;; evil keymap
;;------------------------------------------------------------
(defun vsplit-project-scratch()
  (interactive)
  (+evil/window-vsplit-and-follow)
  (doom/switch-to-project-scratch-buffer)
  )

(defun next-error-middle()
  (interactive)
  (next-error)
  (evil-scroll-line-to-center ())
  )

(defun previous-error-middle()
  (interactive)
  (previous-error)
  (evil-scroll-line-to-center ())
  )

(defun lsp-with-nocompany()
  (interactive)
  (lsp)
  (company-mode)
  )

(defun org-modifiy-mode()
  (interactive)
  (org-mode)
  (read-only-mode -1)
  )

(map! "C-c C-o" #'embark-export)
(map! :leader
      "j8" #'centaur-tabs-backward-tab
      "j9" #'centaur-tabs-forward-tab
      "j*" #'centaur-tabs-backward-tab-other-window
      "j(" #'centaur-tabs-forward-tab-other-window
      "k8" #'org-modifiy-mode
      "k9" #'grep-mode
      "k0" #'ggtags-global-mode

      "ww" #'ace-window
      "hy" #'set-frame-font
      "o1" #'org-overview
      "o2" #'org-show-children
      "ka" #'persp-add-buffer
      "kA" #'persp-remove-buffer
      "kt" #'vterm

      "jw" #'avy-goto-word-0
      ;; "lw" #'avy-goto-word-0
      "jq" #'avy-goto-word-1
      "ja" #'toggle-input-method

      "jn" #'next-error-middle
      "jp" #'previous-error-middle
      "pw" #'doom/open-project-scratch-buffer
      "pq" #'doom/switch-to-project-scratch-buffer


      "km" #'evil-set-marker
      "kM" #'evil-delete-marks
      "dd" #'kill-current-buffer

      ;;---------------------------------------------
      ;; lsp
      ;;---------------------------------------------
      "w;" #'vsplit-project-scratch
      "w:" #'+evil/window-vsplit-and-follow

      ;; "kd" #'lsp-find-de
      "ll" #'lsp
      "lL" #'company-mode
      "kd" #'lsp-find-definition
      "ks" #'lsp-find-references
      "kp" #'lsp-ui-peek-find-references
      "kw" #'lsp-describe-session
      "k=" #'lsp-format-buffer
      "kk" #'clang-format-buffer
      "kl" #'clang-format-region
      "kj" #'flycheck-list-errors
      ;; "kK" #'clang-format-buffer
      "ki" #'lsp-ui-imenu
      )


;; ============================================================================================================
;; use package
;; ============================================================================================================
;;------------------------------------------------------------------
;; rime
;;------------------------------------------------------------------
(use-package! rime
  :custom
  (default-input-method "rime")
  (rime-disable-predicates
   '(
     ;;
     rime-predicate-evil-mode-p
     ;; rime-predicate-prog-in-code-p
     ;; 任意符号开头
     rime-predicate-punctuation-line-begin-p
     ;; 在英文字符串之后（必须为以字母开头的英文字符串）
     rime-predicate-after-alphabet-char-p
     ;; 任意英文字符后
     ;; rime-predicate-after-ascii-char-p
     ;; 在中文字符且有空格之后
     rime-predicate-space-after-cc-p
     ;; 将要输入的为大写字母时
     rime-predicate-current-uppercase-letter-p
     ))
  )
(toggle-input-method)
(rime-lib-select-schema "luna_pinyin_simp")

;;------------------------------------------------------------------
;; youdao
;;------------------------------------------------------------------
(use-package! youdao-dictionary
  :config
  (with-eval-after-load 'evil
    (map! :leader
          ;;---------------------------------------------
          ;; other ui
          ;;---------------------------------------------
          "k1" #'youdao-dictionary-search-at-point+
          "k2" #'youdao-dictionary-search-at-point
          "k3" #'eaf-open-browser-with-history
          "k4" #'eaf-open-browser
          "k5" #'eaf-open-office
          )))

(use-package! ggtags
  :config
  (with-eval-after-load 'evil
    (map! :leader
          "l8" #'ggtags-update-tags

          "l9" #'ggtags-create-tags
          "l0" #'ggtags-delete-tags

          "l1" #'ggtags-find-tag-regexp
          "le" #'ggtags-find-tag-regexp

          "l2" #'ggtags-find-definition
          "ld" #'ggtags-find-definition

          "l3" #'ggtags-find-reference
          "ls" #'ggtags-find-reference

          "l4" #'ggtags-find-other-symbol
          "lr" #'ggtags-find-other-symbol

          "l5" #'ggtags-grep
          "lg" #'ggtags-grep
          )
    ;; (map! "]r" 'real-next)
    ))

;;------------------------------------------------------------------
;; centaur-tabs
;;------------------------------------------------------------------
(use-package! centaur-tabs
  ;; :ensure t
  :config
  (setq centaur-tabs-excluded-prefixes
        '("*epc"
          "*helm"
          "*Helm"
          " *which"
          "*Compile-Log*"
          "*eaf"
          "clangd"
          "*clang"
          "*scratch"
          "*lsp"
          "*LSP"
          "*doom:"
          "*Message"
          "*company"
          "*Flycheck"
          "*Ediff"
          "*ediff"
          "*tramp"
          "*vterm"
          " *Mini"
          "*help"
          "*straight"
          " *temp"
          "*Help"))

  (centaur-tabs-mode t)

  (setq centaur-tabs-height 5)
  (setq centaur-tabs-set-icons nil)
  (setq centaur-tabs-set-close-button nil)
  (setq centaur-tabs-show-new-tab-button nil)
  (setq centaur-tabs-label-fixed-length 12)

  (centaur-tabs-group-by-projectile-project)
  (with-eval-after-load 'evil
    (define-key evil-normal-state-map (kbd "C-8") 'centaur-tabs-backward-tab)
    (define-key evil-normal-state-map (kbd "C-9") 'centaur-tabs-forward-tab))
  (global-set-key (kbd "C-8") 'centaur-tabs-backward-tab)
  (global-set-key (kbd "C-9") 'centaur-tabs-forward-tab)
  (global-set-key (kbd "M-8") 'centaur-tabs-move-current-tab-to-left)
  (global-set-key (kbd "M-9") 'centaur-tabs-move-current-tab-to-right)
  )






















































































;;; 具体参考 mode-line-mule-info 默认值，其中可能有其它有用信息
(setq mode-line-mule-info '((:eval (rime-lighter))))

(add-hook 'c-mode-common-hook
          (lambda ()
            (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
              (ggtags-mode 1)
              )))



(add-to-list 'load-path (expand-file-name "~/.emacs.d"))
(require 'google-c-style)
(add-hook 'c-mode-common-hook 'google-set-c-style)
(add-hook 'c-mode-common-hook 'google-make-newline-indent)


;; 不知道有的地方不行，我过，谁管它啊
(global-set-key (kbd "C-l") nil)
(global-set-key (kbd "C-l") (kbd "C-f"))
(global-set-key (kbd "C-h") nil)
(global-set-key (kbd "C-h") (kbd "C-b"))

















;;------------------------------------------------------------------
;; eaf
;;------------------------------------------------------------------
(add-to-list 'load-path "~/lazycat-emacs/site-lisp/extensions/emacs-application-framework/")
(require 'eaf)
(require 'eaf-browser)
;; (require 'eaf-pdf-viewer)
;;; Code:

;; You need configuration your own local proxy program first.
;; (setq eaf-proxy-type "socks5")
;; (setq eaf-proxy-host "127.0.0.1")
;; (setq eaf-proxy-port "1080")

;; Make `eaf-browser-restore-buffers' restore last close browser buffers.
(setq eaf-browser-continue-where-left-off t)

    ;; ("e" . "")
;; (eaf-bind-key insert_or_edit_url "M-7" eaf-browser-keybinding)

(eaf-bind-key insert_or_edit_url "M-E" eaf-browser-keybinding)
(eaf-bind-key undo_action "C-/" eaf-browser-keybinding)
(eaf-bind-key redo_action "C-?" eaf-browser-keybinding)
(eaf-bind-key scroll_up "M-j" eaf-browser-keybinding)
(eaf-bind-key scroll_down "M-k" eaf-browser-keybinding)
(eaf-bind-key scroll_up_page "M-n" eaf-browser-keybinding)
(eaf-bind-key scroll_down_page "M-p" eaf-browser-keybinding)
;; (eaf-bind-key open_link "M-h" eaf-browser-keybinding)
(eaf-bind-key insert_or_open_link "M-S" eaf-browser-keybinding)
(eaf-bind-key open_link_new_buffer "M-h" eaf-browser-keybinding)
(eaf-bind-key insert_or_open_link_new_buffer "D" eaf-browser-keybinding)
(eaf-bind-key insert_or_open_link_background_buffer "F" eaf-browser-keybinding)
(eaf-bind-key watch-other-window-up-line "M-<" eaf-browser-keybinding)
(eaf-bind-key watch-other-window-down-line "M->" eaf-browser-keybinding)
(eaf-bind-key emacs-session-save "<f5>" eaf-browser-keybinding)
(eaf-bind-key refresh_page "M-r" eaf-browser-keybinding)
(eaf-bind-key insert_or_translate_page "M-;" eaf-browser-keybinding)

(setq eaf-webengine-default-zoom (if (> (frame-pixel-width) 3000) 2 1))
;;(setq eaf-browser-aria2-proxy-host "127.0.0.1")
;;(setq eaf-browser-aria2-proxy-port "9888")
(setq eaf-browser-enable-adblocker t)
(setq eaf-browser-enable-autofill t)
(setq eaf-music-play-order "random")
(setq eaf-marker-letters "JKHLNMUIOYPFDSAVCRREW")
(setq eaf-terminal-font-size 18)
(setq eaf-webengine-font-family "WenQuanYi Micro Hei Mono")
(setq eaf-webengine-fixed-font-family "WenQuanYi Micro Hei Mono")
(setq eaf-webengine-serif-font-family "TsangerJinKai03-6763")
(setq eaf-webengine-font-size 18)
(setq eaf-webengine-fixed-font-size 18)
(setq eaf-terminal-font-family "WenQuanYi Micro Hei Mono")
(setq eaf-jupyter-font-family "WenQuanYi Micro Hei Mono")
(setq eaf-file-manager-show-hidden-file nil)
(setq eaf-music-default-file "/data/Music/")

(setq browse-url-browser-function 'eaf-open-browser)

(defun jekyll-start-server ()
  (interactive)
  (eaf-terminal-run-command-in-dir "jekyll serve --livereload" "/home/andy/manateelazycat.github.io"))

(defun jekyll-open-local ()
  (interactive)
  (eaf-open-browser "http://127.0.0.1:4000"))

(defun eaf-goto-left-tab ()
  (interactive)
  (sort-tab-select-prev-tab))

(defun eaf-goto-right-tab ()
  (interactive)
  (sort-tab-select-next-tab))

(defun eaf-translate-text (text)
  (popweb-dict-bing-input text))

